﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Text;
using System.Windows.Forms;
using DevExpress.Utils;
using DevExpress.XtraEditors;
using WindowsForms.AOnline.Presenter.Dictionary.Stock;
using WindowsForms.AOnline.View.Dictionary;
using WindowsForms.AOnline.WindowsForm.BaseUserControls;
using WindowsForms.AOnline.WindowsForm.FormBase.PropertyGrid;

namespace WindowsForms.AOnline.WindowsForm.UserControl.Dictionary
{
    public partial class UserControlStockList : BaseListUserControl, IStocksView  
    {
        private readonly StocksPresenter _stocksPresenter;   

        public UserControlStockList()
        {
            InitializeComponent();
            _stocksPresenter = new StocksPresenter(this);
        }

        /// <summary>
        /// Deletes the grid.
        /// </summary>
        protected override string DeleteGrid()
        {
            return new StockPresenter(null).Delete(int.Parse(PrimaryKeyValue));
        }

        /// <summary>
        /// Loads the data into grid.
        /// </summary>
        protected override void LoadDataIntoGrid(int page)
        {
            TotalPage = _stocksPresenter.GetPageSize();
            if (page <= TotalPage)
            {
                _stocksPresenter.Display(page);
            }
        }

        public IList<Model.BusinessObjects.Dictionary.StockModel> Stocks
        {
            set
            {
                ListBindingSource.DataSource = value;
                gridView.PopulateColumns(value);

                ColumnsCollection.Add(new XtraColumn { ColumnName = "StockId", ColumnVisible = false, Alignment = HorzAlignment.Center });
                ColumnsCollection.Add(new XtraColumn { ColumnName = "StockCode", ColumnCaption = "Mã kho", ColumnPosition = 1, ColumnVisible = true, ColumnWith = 70 });
                ColumnsCollection.Add(new XtraColumn { ColumnName = "StockName", ColumnCaption = "Tên kho", ColumnPosition = 2, ColumnVisible = true, ColumnWith = 200 });
                ColumnsCollection.Add(new XtraColumn { ColumnName = "Description", ColumnCaption = "Mô tả", ColumnPosition = 3, ColumnVisible = true, ColumnWith = 100 });
                ColumnsCollection.Add(new XtraColumn { ColumnName = "IsActive", ColumnCaption = "Hoạt động", ColumnPosition = 4, ColumnVisible = true, ColumnWith = 100 });
                ColumnsCollection.Add(new XtraColumn { ColumnName = "UnitId",ColumnVisible = false });
            }
        }
    }
}
